define(["../../../carrys/md5","../../../../../js/lib/other/sweet-alert"],function() {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','51');//显示底部文字
    	
    	$scope.telNo = "",$scope.authCode = "",$scope.isbt_disabled = false, $scope.isactive = false, $scope.countdown = 60;
    	
    	var timeOutId;
    	var tempCheckNo = "";
    	//点击获取验证码
    	$scope.getAuthCode = function(){
    		if(! _SYT_util.isValidNo($scope.telNo)){
    			$scope.$emit("promptAlertMsg","手机号无效");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}
    		$scope.isbt_disabled = true;
    		getAuthCode();
    	}

    	//去下一步
    	$scope.goNext = function(){
    		//验证验证码
    		if(tempCheckNo == hex_md5($scope.authCode+"")){
    			changeMobile();
    		}else{
    			$scope.$emit("promptAlertMsg","验证码错误");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    				transData.mobileCheckNo = "";
					$scope.authCode = "";
    			},transData.promptTime);
    		}
    	}

    	//监听是否需要高亮下一步
    	$scope.$watch('authCode', function() {
    		if(($scope.authCode + '').length > 0){
    			changeStyle();
    		}
		});
    	$scope.$watch('telNo', function() {
    		if(($scope.telNo).length > 0){
    			if(($scope.telNo).length == 11){
        			$scope.isClick = true;
        		}else{
        			$scope.isClick = false;
        		}
        		changeStyle();
    		}
		});
    	
    	//修改账号
    	function changeMobile(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.mobileNo = $scope.telNo;
        	bizInfo.mobileCheckNo = $scope.authCode;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("changeMobileNo",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$timeout(function(){
							$scope.$emit("loadingChange",false);
							transData.mobileNo = $scope.telNo;
							$scope.$emit("goNext","/changeMobileSuc");
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接异常");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//切换样式
    	function changeStyle(){
    		if(($scope.telNo).length == 11 && ($scope.authCode + '').length == 6){
				$scope.isactive = true;
			}else{
				$scope.isactive = false;
			}
    	}
    	
    	//请求代理 获取验证码
    	function getAuthCode(){
    		startCountDown();
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.mobileNo = $scope.telNo;
        	bizProxy.queryProxyBizData("sendCheckNo",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
    					tempCheckNo = tempData.body;
		    },function(){});
    	}
    	
    	
    	//开始倒计时
        function startCountDown(){
     	   timeOutId = $interval(function(){
                if (--$scope.countdown == 0){
             	   stopCountDown();
             	   $scope.countdown = 60;
             	   $scope.isbt_disabled = false;
                }
            }, 1000);
        }
        
        //停止倒计时
        function stopCountDown() {
     	   $interval.cancel(timeOutId);
        }
        
      //当键盘被销毁的时候
        $scope.$on("$destroy", function() {
	      	stopCountDown();
	    });
    	
        $scope.$apply();
    }];
});